import 'package:dingtalk/core/model/message_popmenu_model.dart';
import 'package:dingtalk/core/values/values.dart';
import 'package:dingtalk/mock/mock_message.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class THMessagePopMenu extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PopupMenuButton<THMessagePopMenuModel>(
      icon: Icon(Icons.add, size: kSize48),
      onSelected: (THMessagePopMenuModel model) {
        print(model.toString());
      },
      itemBuilder: (context) {
        return <PopupMenuEntry<THMessagePopMenuModel>>[
          ...THMockMessage.messagePopMenuItems
              .map((e) => PopupMenuItem<THMessagePopMenuModel>(
                    value: e,
                    child: THMessagePopMenuItem(
                      text: e.text,
                      iconPath: e.iconPath,
                    ),
                  ))
              .toList()
        ];
      },
    );
  }
}

class THMessagePopMenuItem extends StatelessWidget {
  final String text;

  final String iconPath;

  THMessagePopMenuItem({@required this.text, @required this.iconPath});

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        SvgPicture.asset(iconPath ?? "assets/icons/icon_scan.svg",
            width: kSize40),
        Padding(
          padding: EdgeInsets.only(left: kSize10),
          child: Text(text ?? ""),
        )
      ],
    );
  }
}
